package com.knoya.chejian.pda.util;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by Administrator on 2016/11/26/026.
 */
public class JsonUtil {
    public static String getvolue(JSONObject jo, String key) throws JSONException {
        if(jo.has(key)){
            String s=jo.getString(key);
            if(s.equals("null")){
                return "";
            }else{
                return s;
            }
        }else {
            return "";
        }
    }
    public static int getint(JSONObject jo, String key) throws JSONException {
        if(jo.has(key)){
            return jo.getInt(key);
        }else {
            return -1;
        }
    }
    public static boolean getisvolue(JSONObject jo, String key) throws JSONException {
        if(jo.has(key)){
            return jo.getBoolean(key);
        }else{
            return false;
        }
    }
    public static JSONArray getjsvolue(JSONObject jo, String key) throws JSONException {
        if(getisjo(jo,key)){
            return jo.getJSONArray(key);
        }else{
            return new JSONArray();
        }
    }
    public static JSONObject getjovolue(JSONObject jo, String key) throws JSONException {
        if(getisjo(jo,key)){
            return jo.getJSONObject(key);
        }else{
            return new JSONObject();
        }
    }
    public static boolean getisjo(JSONObject jo, String key) throws JSONException {
        if(jo.has(key)){
            if(jo.getString(key).equals("") || jo.getString(key).equals("null")){
                return false;
            }else{
                return true;
            }
        }else{
            return false;
        }
    }
    public static void toost(String data){
        try{
            JSONArray js=new JSONArray(data);
            Myutil.MyTost(js.getString(0));
        }catch (JSONException e){
            e.printStackTrace();
        }
    }
}
